package com.ruoyi.project.distribute.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.distribute.domain.HosCompany;
import com.ruoyi.project.distribute.service.IHosCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 生产厂家控制层方法
 * @author anran
 */
@RestController
@RequestMapping("/distribute/company")
public class HosCompanyController extends BaseController
{
    @Autowired
    private IHosCompanyService hosCompanyService;

    /**
     * 查询生产厂家信息
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('distribute:company:list')")
    public TableDataInfo list(HosCompany hosCompany)
    {
        startPage();
        List<HosCompany> list = hosCompanyService.selectByHosCompanyList(hosCompany);
        return getDataTable(list);
    }


    /**
     * 新增生产厂家信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:add')")
    @Log(title = "生产厂家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosCompany hosCompany)
    {
        return toAjax(hosCompanyService.insertHosCompany(hosCompany));
    }

    /**
     * 删除生产厂家信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:remove')")
    @Log(title = "生产厂家信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(hosCompanyService.deleteHosCompanyByIds(companyIds));
    }

    /**
     * 导出生产厂家信息列表
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:export')")
    @Log(title = "生产厂家信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HosCompany hosCompany)
    {
        List<HosCompany> list = hosCompanyService.selectByHosCompanyList(hosCompany);
        ExcelUtil<HosCompany> util = new ExcelUtil<HosCompany>(HosCompany.class);
        return util.exportExcel(list, "生产厂家");
    }

    /**
     * 根据ID查询生产厂家信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return AjaxResult.success(hosCompanyService.selectHosCompanyById(companyId));
    }

    /**
     * 修改生产厂家信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:edit')")
    @Log(title = "修改生产厂家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HosCompany hosCompany)
    {
        hosCompany.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(hosCompanyService.updateHosCompany(hosCompany));
    }


}
